﻿using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MESMian.EntityMapping
{
    public class DevicesMapping : IEntityTypeConfiguration<Devices>
    {
        public void Configure(EntityTypeBuilder<Devices> builder)
        {
            builder.ToTable("Devices");
            builder.HasKey(d => d.DeviceId);
            builder.Property(d => d.DeviceId)
                .HasComment("设备主键，自动编号");

            builder.Property(d => d.DeviceCode)
                .IsRequired()
                .HasColumnType("varchar(20)")
                .HasComment("设备编码，不能重复");

            builder.Property(d => d.DeviceName)
                .IsRequired()
                .HasColumnType("varchar(30)")
                .HasComment("设备名称，不能重复");

            builder.Property(d => d.DeviceCategoryId)
                .IsRequired()
                .HasColumnType("int")
                .HasComment("设备类型，外键（DeviceCategories）");

            builder.Property(d => d.DeviceSpecId)
                .IsRequired()
                .HasColumnType("int")
                .HasComment("设备规格，外键（DeviceSpecs）");

            builder.Property(d => d.DeviceUnitId)
                .IsRequired()
                .HasColumnType("int")
                .HasComment("单位，外键（Units）");

            builder.Property(d => d.DeviceStatus)
                .IsRequired()
                .HasColumnType("int")
                .HasDefaultValue(0)
                .HasComment("设备状态（0在库中，1使用中，2维修中，3其他），默认值0");

            builder.Property(d => d.RegisterId)
                .IsRequired()
                .HasColumnType("int")
                .HasComment("登录人，外键（Users）");

            builder.Property(d => d.RegisterTime)
                .IsRequired()
                .HasColumnType("datetime")
                .HasComment("登录日期");

            builder.Property(d => d.Remark)
                .HasColumnType("varchar(150)")
                .HasComment("备注");

            builder.Property(d => d.Status)
                .IsRequired()
                .HasColumnType("int")
                .HasDefaultValue(0)
                .HasComment("数据状态（0正常，1删除），默认值0");

            builder.Property(d => d.CreateUserId)
                .IsRequired()
                .HasColumnType("int")
                .HasComment("创建人，外键（Users）");

            builder.Property(d => d.CreateTime)
                .IsRequired()
                .HasColumnType("datetime")
                .HasDefaultValueSql("GETDATE()")
                .HasComment("创建时间，默认值为当前时间");

            builder.Property(d => d.LastUpdateUserId)
                .HasColumnType("int")
                .HasComment("最后一次修改人，外键（Users）");

            builder.Property(d => d.LastUpdateTime)
                .HasColumnType("datetime")
                .HasComment("最后一次修改时间");
        }
    }

}
